package com.mf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mf.entity.TaskDetail;
import com.mf.entity.TaskDetailDto;
import com.mf.mapper.TaskDetailMapper;
import com.mf.service.ITaskDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * <p>
 * 任务明细 服务实现类
 * </p>
 *
 * @author mf
 * @since 2024-04-13
 */
@Service
public class TaskDetailServiceImpl extends ServiceImpl<TaskDetailMapper, TaskDetail> implements ITaskDetailService {
    @Resource
    private TaskDetailMapper taskDetailMapper;

    @Override
    public List<TaskDetail> findByTIds(List<Integer> ids) {
        final LambdaQueryWrapper<TaskDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(TaskDetail::getTId, ids);
        final String date = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        queryWrapper.eq(TaskDetail::getDate,date);

        return taskDetailMapper.selectList(queryWrapper);
    }

    @Override
    public List<TaskDetail> getByTId(Integer id) {
        return taskDetailMapper.getByTId(id);
    }

    @Override
    public List<TaskDetail> getByTIdAndDate(TaskDetailDto taskDetailDto) {
        final LambdaQueryWrapper<TaskDetail> queryWrapper = new LambdaQueryWrapper<>();
        // 将 TaskDetailDto 中tid 设置到查询条件中
        if(taskDetailDto.getTId() != null){
            queryWrapper.eq(TaskDetail::getTId, taskDetailDto.getTId());
        }
        // 设置查询日期范围
        queryWrapper.between(TaskDetail::getDate, taskDetailDto.getStartDate(), taskDetailDto.getEndDate());
        return taskDetailMapper.selectList(queryWrapper);

    }
}
